
function _addZreo(val) {
    return val < 10 ? ('0' + val) : val;
}
// 时间处理函数
function formateDateTime(timeDate) {
    const date = new Date(timeDate);
    const y = date.getFullYear(),
        m = _addZreo(date.getMonth() + 1),
        d = _addZreo(date.getDate()),
        h = _addZreo(date.getHours()),
        min = _addZreo(date.getMinutes()),
        s = _addZreo(date.getSeconds());

    return `${y}/${m}/${d} ${h}:${min}:${s}`;
}
//时间处理函数
function formateTodayDay(timeDate) {
    const date = new Date(timeDate);
    const options = { weekday: "long" };
    const m = date.toLocaleDateString("en-US", options).slice(0, 3);
    return `${m}`;
}
//时间处理函数
function formataTodayTime(tiemDate) {
    const date = new Date(tiemDate);
    const m = date.getMonth() + 1,
        d = _addZreo(date.getDate());
    return `${m}月${d}日`;
}
//处理data函数
function formatDataWeekDay(data) {
    const listDay = _getDateForWeek();
    const mon = listDay[0],
        tue = listDay[1],
        wed = listDay[2],
        thu = listDay[3],
        fri = listDay[4],
        sat = listDay[5],
        sun = listDay[6];
    const newData = data.filter(item => formataTodayTime(item.id) === mon || formataTodayTime(item.id) === tue || formataTodayTime(item.id) === wed || formataTodayTime(item.id) === thu || formataTodayTime(item.id) === fri || formataTodayTime(item.id) === sat || formataTodayTime(item.id) === sun);
    return newData;
}
//获取一周的日期数组
function _getMonDate()
{
let d=new Date(),
day=d.getDay(),
date=d.getDate();
// eslint-disable-next-line eqeqeq
if(day==1)
return d;
// eslint-disable-next-line eqeqeq
if(day==0)
d.setDate(date-6);
else
d.setDate(date-day+1);
return d;
}

function _getDateForWeek(){
    let d=_getMonDate();
        let arr=[];
        for(let i=0; i<7; i++)
        {
        arr.push((d.getMonth()+1)+'月'+ _addZreo(d.getDate())+'日');
        d.setDate(d.getDate()+1);
        }
        return arr;
}

//echarts处理函数
const getPieOption = (incData, comData, title) => {
    return {
        title: {
            text: title,
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
        },
        series: [
            {
                name: '本地数据',
                type: 'pie',
                radius: '50%',
                data: [
                    { value: incData, name: '已完成' },
                    { value: comData, name: '未完成' }
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    }
}
//echarts处理函数
const getLineOption = (yData, title) => {
    return {
        title: {
            text: title,
            left: 'center'
        },
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
            name: '事件数',
            data: [yData.mon, yData.tue, yData.wed, yData.thu, yData.fri, yData.sat, yData.sun],
            type: 'bar',
            barWidth: '40%',
            itemStyle: {
                //修改圆角
                borderRadius: 5,
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: '#48c78e' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#fff' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            }
        }
    ]
    }
}

export {
    formateDateTime,
    formateTodayDay,
    formataTodayTime,
    formatDataWeekDay,
    getPieOption,
    getLineOption
};
